Bring GtkPrintContext hard margin aware
authorecyrbe <ecyrbe@gmail.com>
Sat, 5 Dec 2009 12:23:44 +0000 (13:23 +0100)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Sat, 5 Dec 2009 12:23:44 +0000 (13:23 +0100)
See bug #468989.

gtk/gtk.symbols
gtk/gtkprintcontext.c
gtk/gtkprintcontext.h

index 40f3261c66fac55c011cac3bef01029be351b196..1b61ca7499b097c22baba0e4e4f7de00b473d502 100644 (file)
@@ -2918,6 +2918,7 @@ gtk_print_context_get_width
 gtk_print_context_get_height
 gtk_print_context_get_dpi_x
 gtk_print_context_get_dpi_y
+gtk_print_context_get_hard_margins
 gtk_print_context_get_pango_fontmap
 gtk_print_context_create_pango_context
 gtk_print_context_create_pango_layout
index 80eac79fa75424c85f7ddeae19428633a4acf55e..cdf04d7c2f539bb3d371ee13d2413622c21fcfab 100644 (file)
@@ -44,6 +44,13 @@ struct _GtkPrintContext
   
   gdouble pixels_per_unit_x;
   gdouble pixels_per_unit_y;
+
+  gboolean has_hard_margins;
+  gdouble hard_margin_top;
+  gdouble hard_margin_bottom;
+  gdouble hard_margin_left;
+  gdouble hard_margin_right;
+
 };
 
 struct _GtkPrintContextClass
@@ -90,6 +97,7 @@ _gtk_print_context_new (GtkPrintOperation *op)
 
   context->op = op;
   context->cr = NULL;
+  context->has_hard_margins = FALSE;
   
   return context;
 }
@@ -373,6 +381,62 @@ gtk_print_context_get_dpi_y (GtkPrintContext *context)
   return context->surface_dpi_y;
 }
 
+/**
+ * gtk_print_context_get_hard_margins:
+ * @context: a #GtkPrintContext
+ * @top: top hardware printer margin
+ * @bottom: bottom hardware printer margin
+ * @left: left hardware printer margin
+ * @right: right hardware printer margin
+ *
+ * Obtains the hardware printer margins of the #GtkPrintContext, in units.
+ *
+ * Return value: %TRUE if the hard margins were retrieved
+ *
+ * Since: 2.20
+ */
+gboolean
+gtk_print_context_get_hard_margins (GtkPrintContext *context,
+                                   gdouble         *top,
+                                   gdouble         *bottom,
+                                   gdouble         *left,
+                                   gdouble         *right)
+{
+  if (context->has_hard_margins)
+    {
+      *top    = context->hard_margin_top / context->pixels_per_unit_y;
+      *bottom = context->hard_margin_bottom / context->pixels_per_unit_y;
+      *left   = context->hard_margin_left / context->pixels_per_unit_x;
+      *right  = context->hard_margin_right / context->pixels_per_unit_x;
+    }
+
+  return context->has_hard_margins;
+}
+
+/**
+ * gtk_print_context_set_hard_margins:
+ * @context: a #GtkPrintContext
+ * @top: top hardware printer margin
+ * @bottom: bottom hardware printer margin
+ * @left: left hardware printer margin
+ * @right: right hardware printer margin
+ *
+ * set the hard margins in pixel coordinates
+ */
+void
+_gtk_print_context_set_hard_margins (GtkPrintContext *context,
+                                    gdouble          top,
+                                    gdouble          bottom,
+                                    gdouble          left,
+                                    gdouble          right)
+{
+  context->hard_margin_top    = top;
+  context->hard_margin_bottom = bottom;
+  context->hard_margin_left   = left;
+  context->hard_margin_right  = right;
+  context->has_hard_margins   = TRUE;
+}
+
 /**
  * gtk_print_context_get_pango_fontmap:
  * @context: a #GtkPrintContext
index 9bd13343cc1fc6d2443916df22de47aeeb3ac3b0..30572d6835c2eab03b2ba6eab487ddb5037bd929 100644 (file)
@@ -49,6 +49,11 @@ gdouble       gtk_print_context_get_width            (GtkPrintContext *context);
 gdouble       gtk_print_context_get_height           (GtkPrintContext *context);
 gdouble       gtk_print_context_get_dpi_x            (GtkPrintContext *context);
 gdouble       gtk_print_context_get_dpi_y            (GtkPrintContext *context);
+gboolean      gtk_print_context_get_hard_margins     (GtkPrintContext *context,
+                                                     gdouble         *top,
+                                                     gdouble         *bottom,
+                                                     gdouble         *left,
+                                                     gdouble         *right);
 
 /* Fonts */
 PangoFontMap *gtk_print_context_get_pango_fontmap    (GtkPrintContext *context);